package com.iter.devbox.pattern.composite;

import java.util.ArrayList;
import java.util.List;

/**树枝构件*/
public class Composite implements Component {
	
	private List<Component> mList = new ArrayList<Component>();
	
	private String name;
	
	public Composite(String name) {
		this.name = name;
	}

	@Override
	public void add(Component component) {
		mList.add(component);
	}

	@Override
	public void remove(Component component) {
		mList.remove(component);
	}

	@Override
	public void display() {
		System.out.println("我是：" + name);
		if (mList.size()>0) {
			for (Component component : mList) {
				component.display();
			}
		}
	}
}
